from django.shortcuts import render

# Create your views here.
from rest_framework.views import APIView
from rest_framework.views import Response
import json
class Report(APIView):
    def get(self,request):
        context=dict()
        context['err_code']=0
        return Response(context)
    def post(self,request):
        data = json.loads(request.body)  # 解析json数据
        if (data['post_type']) == 'message' and data['message_type'] == 'private':
            message = Message(user=str(data['user_id']), message=data['message'], time=data['time'])
            message.handle()
        return Response({})  # 根据酷Qhttpapi插件的作者所说，这里可以返回空的body
class Message:
    def __init__(self, user, message, time):
        self.user = user  # 发送者
        self.message = message  # 消息
        self.time = time  # 时间戳

    def handle(self):
        print("收到一条来自{}的消息：{}".format(self.user, self.message))